package com.woniuxy.goods.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.woniuxy.commons.Goods;

import com.woniuxy.commons.annotation.RequirePermission;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: 15489  <br/>
 * Date: 2022/3/25:11:52  <br/>
 * Description:
 */

@RestController
@RequestMapping("/goods")
public class goodsController {
    @GetMapping("/all")
    @HystrixCommand(fallbackMethod = "abc")
    public List<Goods> all(){
//        假设从数据库得到的数据
        List<Goods> goodsList=new ArrayList<>();
        goodsList.add(new Goods(1001,"烤鸭饭",90));
        goodsList.add(new Goods(1002,"烤饭",190));
        goodsList.add(new Goods(1003,"鸭饭",290));
//        返回数据
        return goodsList;
    }
    public List<Goods> abc(){
        return null;
    }
    @RequirePermission(value = "goods::find")
    @GetMapping("/find/{id}")
    public Goods find(@PathVariable("id") int id){
        System.out.println(id);
        return new Goods(1001,"烤鸭饭",90);
    }
    @RequirePermission(value="goods::add")
    @PostMapping("/add")
    public boolean add(@RequestBody Goods goods){
        System.out.println(goods);
        return true;
    }

    @PutMapping("/updata")
    public  void updata(@RequestBody Goods goods){
        System.out.println(goods);
    }


    @DeleteMapping("/del/{id}")
    public  void  del(@PathVariable("id") int id){
        System.out.println(id);

    }
}
